<?php
/*
---------------------------------------------------------------------------
alerts/active_data.php for SALAM Frontend

Copyright 2009, 2010 Jacob McEntire

    This file is part of SALAM.

    SALAM is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SALAM is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SALAM.  If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
*/
require_once("../../library/frontend.php");

$active_alert_result = run_query("SELECT hosts.name, triggers.name, alerts.type, alerts.current_info, alerts.current_data, alerts.start_time, alerts.last_check FROM hosts, triggers, alerts WHERE alerts.active = 1 AND alerts.host_id = hosts.id AND alerts.trigger_id = triggers.id ORDER BY alerts.start_time DESC");
if (mysql_num_rows($active_alert_result) != NULL) {
	echo '<table class="alerts"><tr><th>Host:</th><th>Trigger:</th><th>State:</th><th>Start Time:</th><th>Last Check:</th><th>Info:</th><th>Data:</th></tr>';
	while(list($host_name, $trigger_name, $alert_type, $current_info, $current_data, $start_time, $last_check) = mysql_fetch_array($active_alert_result))	{
		switch ($alert_type) {
		case 0:
			$alert_type = "OK";
			break;
		case 1:
			$alert_type = "Warning";
			break;
		case 2:
			$alert_type = "Critical";
			break;
		default:
			$alert_type = "ERROR";
			break;
		}
		echo '<tr class="', $alert_type, '"><td>', $host_name, '</td><td>', $trigger_name, '</td><td>', $alert_type, '</td><td>', date("D M j G:i:s T Y", $start_time), '</td><td>', date("D M j G:i:s T Y", $last_check), '</td><td>', $current_info, '</td><td>', $current_data, '</td></tr>';
	}
	echo '</table>';
}
else
	echo '<h3>No Active Alerts</h3>';
echo '<div class="current_time">Current Date/Time: ', date("D M j G:i:s T Y"), '</div>';
?>